<!--写月报-->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>学生端提交月报页</title>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/timecontrol.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<style type="text/css" media="screen">
			body html {
				background-color: white;
			}
			.title {
				font-size: 14px;
			}
			.summary_div .feeling {
				padding-bottom: 1px;
				padding-left: 14px;
			}
			.feeling {
				border-bottom: 1px solid #ededed;
			}
			.title {
				border-left: unset;
			}
			.content_div {
				margin-top: 66px
			}
			.comment_div {
				padding-right: 20px;
				margin-top: 10px
			}
			.score_div .feeling-text {
				/*text-indent: 2em;*/
				background-size: 16px;
				margin-top: 15px;
				margin: 10px;
			}
			.score_div .feeling-text p {
				color: #646464;
				padding: 2px 2px;
			}
			.score_div {
				padding: 2px 5px;
				background: #fff
			}
			.star_score_div {
				padding: 19px 10px;
				padding-left: 18px;
			}
			.star_score_div	.myScore-starscore .star img {
				margin-left: 1%;
				width: 18px;
			}
			.star {
				width: 53%;
			}
			.title img {
				height: 20px;
				padding-top: 4px
			}
			.summary_title {
				display: inline-block;
				background: url(../../icon/icon_summary_title.png) no-repeat left center;
				background-size: 18px;
				padding-left: 25px;
			}
			.timeImgSpan {
				display: inline-block;
				background: url(../../icon/icon_timespan.png) no-repeat left center;
				background-size: 16px;
				padding-left: 25px;
			}
			.attachment_title {
				display: inline-block;
				background: url(../../icon/icon_attachment.png) no-repeat left center;
				background-size: 20px;
				padding-left: 25px;
			}
			.padding25 {
				padding-left: 1px;
				border-bottom: 1px solid #ededed;
			}
			.bottom_btn_div {
				color: #FFF;
				height: 45px;
				width: 100%;
				z-index: 995;
				border-top: 1px solid #d9d9d9;
				position: fixed;
				bottom: 0px;
				left: 0px;
				text-align: center;
				margin-top: 23px;
			}
			.bottom_btn_div a {
				line-height: 45px;
				font-size: 14px;
				background: #18b4ed;
				width: 100%;
				color: #FFF;
			}
			.writeReport .ReviewWeekly_div {
				margin-top: 0px;
			}
			.attachment_div{
			padding-left: 10px;
			padding-right: 8px;
			}
		</style>
	</head>
	<body>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item" href="#" onclick="showAlert()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>写月报</span>
			<a class="base_right_item base_hide_item" href="#"> </a>
		</div>
		<div class=" writeReport"style="margin-top: 65px">
			<div data-role="fieldcontain" class="timecontrol bgwhite padding25" id="">
				<span class="font16 base_dark_grey left_15 timeImgSpan font14">提交日期</span>
				<input type="text" id="time" class="timeipt right font14"  readonly="readonly"/>
			</div>
			<div class="ReviewWeekly_div  summary_div">
				<div class="feeling">
					<p class="title summary_title" >
						月工作总结
					</p>
				</div>
				<div class="score_div">
					<div class="feeling-text" style="margin-bottom: -8px">
						<textarea class="textarea_t top_10" id="summary"  placeholder='字数不得少于5个字'></textarea>
					</div>
				</div>
			</div>
			<div class="ReviewWeekly_div  summary_div">
				<div class="feeling">
					<p class="title  attachment_title" >
						附件内容
					</p>
				</div>
				<div class="score_div">
					<div class="fileDiv attachment_div" id="imgDiv" >
						<ul id="ul1" class=""></ul>
					</div>
				</div>
			</div>
			<!--	<div class="myScore top_10 "style=" width: 100%">
			<p class="title  attachment_title" >
			添加附件
			</p>
			<div class="fileDiv " id="imgDiv" >
			<ul id="ul1" class=""></ul>
			</div>
			</div>-->
			<!--	<button id="sumbit_bt" type="button" class=" top_30 bottom_30  mui-btn btns mui-btn-block  " onclick="Upload_data()" disabled="true">
			提交
			</button>-->
			<div class="bottom_btn_div" id="sub_div" onclick="Upload_data()">
				<a>提交</a>
			</div>
		</div>
		<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title">是否放弃在此页面操作？</strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
					<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
	</body>
	<script src="../../script/mui.min.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script src="../../script/timecontrol.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/mui.min.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/timeStampTool.js"></script>
	<script src="../../script/processing_images.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/base64.min.js"></script>
	<script type="text/javascript">
		//附件地址集合
		var urlArr = new Array();
		//上传后的图片路径对象
		var picurls = [];
		//文件大小
		var SizeArr = [];
		var FileArr = new Array();
		//文件名
		var NameArr = [];
		var sxtdScore = 0;
		var cqlScore = 0;
		var gzwcdScore = 0;
		var jnzwdScore = 0;
		var summary = '';
		var experience = '';
		var count = 0;
		//空格回车正则判断
		var parten = /^\s*$/;
		//百度云返回的文件地址
		//		var num = 0;
		var sxtypes = '';
		var str = '';
		var arr = new Array('jpg', 'gif', 'png', 'jpeg', 'bmp', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'pdf', 'txt');
		var FileFormatArr = new Array('doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'pdf', 'txt');
		var ImgFormatArr = new Array('jpg', 'gif', 'png', 'jpeg', 'bmp');
		var pid = "";
		var apiready = function() {
			//			SendBehaviorTrajectoriesNotifi('0', '学生端提交月报', '095');
			sendBuriedNotifi('0', '学生端提交月报', '095');
//			//选择时间
            $("#time").val(timeStringWithTimeStamp(currentDateTime()))
			//获取学生实习计划状态
			judgePracticeType();
//			setupStarClick();
			backKey();
			listfile();
			listenScroll();
		}
		
		 function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		// 滚动监听
		function listenScroll() {
		
			var winHeight = $(window).height();
			$(window).resize(function() {
				var thisHeight = $(this).height();
				if (winHeight - thisHeight > 50) {
					//当软键盘弹出，在这里面操作
					$("#sub_div").css('display', 'none');
				} else {
					$("#sub_div").css('display', 'block');
					//当软键盘收起，在此处操作
				}
			});
		}
		//学生端获取实习计划状态（仅限学生端）
		function judgePracticeType() {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid')
			};
			cfnetppPOST(urlPracticeType, param, true, function(data, status) {
				if (status == 'success') {
//										alert(JSON.stringify(data));
					//1,成功，返回success
					if (data.status == 1) {
						var list = data.json;
						if (list != null && list != '') {
							sxtypes = parseInt(list.sxtypes);
							pid = list.id;
							//0：顶岗，1：认知，2:跟岗
							if (sxtypes != 1) {
								$('#sumbit_bt').unbind('click').addClass('mui-btn-warning').removeClass('btns').attr('disabled', false);
								if (sxtypes == 0) {
									$('#dgsx').show();
								}
							}
						} else {
							ShowToast('你还未有实习计划，请等待分配');
						}
					} else if (data.status == -1) {
						ShowToast('你还未有实习计划，请等待分配');
					} else {
						ShowToast('你还未有实习计划，请等待分配');
					}
				}
			})
		}

		//UI显示
		function listfile() {
			//			$("#ul1").html('');
			var num = FileArr.length;
			var imageHtmls = '';
			var str2 = "支持附件最大附件大小:10M;仅支持以下格式:('jpg', 'gif', 'png', 'jpeg', 'bmp', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'pdf', 'txt')";
			if (num > 0 && num < 11) {
				for (var i = 0; i < num; i++) {
					var imageHtml = '<li dataid="' + num + '"  class="mui-table-view-cell " >' + '<a class=" base_content_font" href="#" >' + '<span class="base_grey left_text">' + FileArr[i].filename + '</span>' + ' <span id="company_name " class="base_grey right_text padding_left_10">' + bytesToSize(FileArr[i].filesize) + '</span> <img class="  right"    src="../../image/remove.png"  width="20" height="20"  onClick="deleteImg(' + i + ')" >' + '</a>' + '</li>';
					imageHtmls = imageHtmls + imageHtml;
					//					alert(imageHtmls);
				}
			}
			if (num < 10) {
				var seleimg = '<a href="javascript:;" class="weui_btn weui_btn_mini weui_btn_default top_10" onclick="AddFile()">' + '添加附件' + '</a>' + '<span style="margin-left: 5px"class="font11">' + str2 + '</span>' + '</div>';
				imageHtmls = imageHtmls + seleimg;
			}
			$("#ul1").html(imageHtmls);
		}

		//删除附件
		function deleteImg(i) {
			FileArr.splice(i, 1);
			urlArr.splice(i, 1);
			listfile();
		}

		//添加附件
		function AddFile() {
			if (api.systemType == "ios") {
				ShowToast('ios暂不支持提交附件，请在pc平台或android平台下提交');
			} else {
				var fileBrowser = api.require('fileBrowser');
				fileBrowser.open(function(ret, err) {
					if (ret) {
						//文件地址
						var url = ret.url;
						fileBrowser.close();
						//文件名
						var fileName = splitFileName(url);
						//文件后缀ming
						var ext = fileName.replace(/.+\./, "");
						//小写格式
						var extLower = ext.toLowerCase();
						////根据文件地址判断文件大小是否超过10M
						var fs = api.require('fs');
						fs.getAttribute({
							path : url
						}, function(ret, err) {
							var fileSize = ret.attribute.size;
							//大小，10M转换为b
							if (ret.attribute.size > 10485760) {
								ShowToast('上传的文件过大');
							} else if (arr.toString().indexOf(extLower) == -1) {
								ShowToast('文件格式不符合要求');
							} else if (urlArr.toString().indexOf(url) > -1) {
								ShowToast('不允许重复提交');
							} else {
								urlArr.push(url);
								var num = urlArr.length;
								var data = {
									filepath : url,
									filename : fileName,
									filesize : fileSize,
								};
								FileArr.push(data);
								listfile();
								if (num > 0) {
									api.showProgress({
										style : 'default',
										animationType : 'fade',
										title : '努力加载中...',
										text : '文件上传中...',
										modal : true
									});
									if (ImgFormatArr.toString().indexOf(extLower) != -1) {//图片格式文件
										//上传图片文件到阿里云
										UploadFile_ali(Upload_File_img, url, function(ret) {
											//判断是否上传完成
											FileArr[num - 1].filepath = ret.fileurl;
											var k = FileArr.length;
											if (k == num) {
												str = FileArr;
												hideProgress();
											}
										});
									} else {//文档格式文件
										//上传文档格式至阿里云
										UploadFile_ali(Upload_File_file, url, function(ret) {
											//判断是否上传完成
											FileArr[num - 1].filepath = ret.fileurl;
											var k = FileArr.length;
											if (k == num) {
												str = FileArr;
												hideProgress();
											}
										});
									}
								} else {
									str = '';
								}
							}
						});
					}
				});
			}
		}

		function Upload_data() {
			//		SendBehaviorTrajectoriesNotifi('1', '学生端提交月报', '095');
			summary = $('#summary').val();
			var monthtime = timeStampWithString($('#time').val());
			var exper = '';
			if (experience == null || experience.length <= 0) {
				exper = '无';
			} else {
				exper = experience;
			}
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				monthtime : monthtime,
				summary : Base64.encode(summary),
				urldata : str,
				experience : Base64.encode(exper),
				sxtd : sxtdScore, //实习态度(返回分值最高10分)
				cql : cqlScore, //出勤率
				gzwcd : gzwcdScore, //工作完成度
				jnzwd : jnzwdScore,
				pid : pid,
				message : '月报'
			};
			
			if (summary.length == 0 || parten.test(summary)) {
				ShowToast('提交信息不完整，请完善信息后再次提交');
			} else if (summary.length < 5) {
				ShowToast('字数不得小于5个字');
			} else if (summary.length > 5000) {
				ShowToast('字数不得大于5000个字');
			}
//			 else if ((sxtypes == "0" ) && (sxtdScore == 0 || cqlScore == 0 || gzwcdScore == 0 || jnzwdScore == 0)) {
//				ShowToast('你还未完成对企业师傅的评分，请评分');
//			} 
			else {
				showProgress();
				cfnetppPOST(urlMonth, param, false, function(data, status) {
					hideProgress();
					SendBusinessOperationsLogNotifi('学生端提交月报', '095', param, param, '', data, '提交月报接口', '095-01')
					if (status == 'success') {
						//1,成功，返回success
						if (data.status == 1) {
							ShowToast('提交成功');
							//发送通知，使月报列表接收通知，开始刷新周报列表
							sendNotifi();
							setTimeout(function() {
								backClick();
							}, 500);
							//3,未分配,返回job
						} else if (data.status == 3) {
							ShowToast('您处于未实习状态，暂不能提交月报!');
							//2,您本月已提交过月报,返回has
						} else if (data.status == 2) {
							ShowToast('您本月已提交过月报!');
							//4,选择时间不在正确时间内，返回sxtime
						} else if (data.status == 4) {
							ShowToast('请选择实习时间内的日期！');
							//5,实习报告已通过,已结业,返回end
						} else if (data.status == 5) {
							ShowToast('你本次实习已经结业啦，不用再提交了!');
						} else {
							ShowToast(data.message);
						}
					} else {
						ShowToast('网络异常,请检查网络!');
					}
				});
			}
		}

		function backKey() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				showAlert();
			});
		}

		function showAlert() {
			summary = $('#summary').val();
			if (summary.length > 0) {
				$('#offlineAlert').show();
			} else {
				backClick();
			}
		}

		function backClick() {
			sendBuriedNotifi('1', '学生端提交月报', '095');
			api.closeWin({
			});
		}

		function cleanCancel() {
			$('#offlineAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			backClick();
		}

		//发送通知给未审核列表刷新页面
		function sendNotifi() {
			api.sendEvent({
				name : 'RefreshMonthNotifi'
			});
		}

		function setupStarClick() {
			$('.star img').each(function(i) {
				$(this).click(function() {
					$(this).attr('src', '../../image/icon_xingxing.png');
					$(this).prevAll().attr('src', '../../image/icon_xingxing.png');
					$(this).nextAll().attr('src', '../../image/icon_xingxing01.png');
					var score = ($(this).prevAll().length + 1) * 5;
					if ($(this).parent().attr('id') == 'taiduNum') {//实习态度
						sxtdScore = score;
					} else if ($(this).parent().attr('id') == 'chuqinNum') {//出勤率
						cqlScore = score;
					} else if ($(this).parent().attr('id') == 'gzwcdNum') {//工作完成度
						gzwcdScore = score;
					} else if ($(this).parent().attr('id') == 'jnzwdNum') {//技能掌握度
						jnzwdScore = score;
					}
				})
			});
		}

//		//选择时间插件
//		function prepareData() {
//			var currenttime = new currentTime();
//			//当前时间   currenttime.currentDate当前日期 currenttime.currentTime当前时间  currenttime.currentDatetime当前日期时间
//			var curr = currenttime.year;
//			timeInit(curr);
//			// 时间控件
//			//			var currenttime = new currentTime();
//			$("#time").val(currenttime.currentDate);
//			$("#time").change(function() {
//				var setDate = $("#time").val();
//				var d = new Date(Date.parse(setDate.replace(/-/g, "/")));
//				var curDate = new Date();
//				if (d > curDate) {
//					ShowToast("请选择正确的日期！");
//					$("#time").val(currenttime.currentDate)
//				}
//			});
//		}
//
//		function timeInit(curr) {
//			// 如需修改类型 date是年月日 time是24小时时间 datetime是时期和时间
//			$('#time').mobiscroll().date({
//				dateFormat : 'yyyy-mm-dd',
//				lang : 'zh',
//				//				startDay : 1,//开始日期
//				//				startMonth : 0, // 开始月份
//				startYear : curr, //开始年份
//				endYear : curr + 1//结束年份
//			});
//		}
	</script>
</html>